/**
 * 版权所有 2009-2015 中国中医科学院中医药信息研究所 何前锋 frontpeak@yahoo.com.cn
 **/
package cn.ac.cintcm.sh.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Map.Entry;

public class Qi9 {

    public static final String ROOT = "root";
    private static HashMap<String, Float> nameValue;
    private static HashMap<String, String> parent;
    public static float q = 10f;
    public static float MinValue = 0;
    public static float MaxValue = 0;
    
    static {
        float value = 1;
        nameValue = new HashMap<String, Float>();
        nameValue.put("平", 0f);
        nameValue.put("微温", 1f);
        nameValue.put("凉", -1f);
        value = q * value;
        nameValue.put("温", value);
        nameValue.put("微寒", -1 * value);
        value = q * value;
        nameValue.put("热", value);
        nameValue.put("寒", -1 * value);
        value = q * value;
        MaxValue = value;
        MinValue = -1 * value;
        
        nameValue.put("大热", value);
        nameValue.put("大寒", -1 * value);
        nameValue.put("温热", 1f);
        nameValue.put("寒凉", 1f);
        nameValue.put("气", 1f);
        
        parent = new HashMap<String, String>();
        parent.put("气", ROOT);
        parent.put("温热", "气");
        parent.put("平", "气");
        parent.put("寒凉", "气");
        parent.put("大热", "温热");
        parent.put("热", "温热");
        parent.put("温", "温热");
        parent.put("微温", "温热");
        parent.put("凉", "寒凉");
        parent.put("微寒", "寒凉");
        parent.put("寒", "寒凉");
        parent.put("大寒", "寒凉");
    }
    
    public static float getValue(String qi) {
        Float value = nameValue.get(qi);
        if (value == null) {
            value = 0f;
            System.out.println(qi + " 找不到气");
        }
        return value;
    }
    
    public static String getParent(String qi) {
        return parent.get(qi);
    }
    
    public static List<String> getChildren(String qi) {
        List<String> list = new ArrayList<String>();
        Set<Entry<String, String>> entries = parent.entrySet();
        for( Entry<String, String> entry : entries) {
            if (entry.getValue().equals(qi)) {
                list.add(entry.getKey());
            }
        }
        return list;
    }
    
    public static List<String> getNonLeafChildren(String qi) {
        List<String> list = new ArrayList<String>();
        if (qi.equals("气") || qi.equals(ROOT)) {
            Set<Entry<String, String>> entries = parent.entrySet();
            for( Entry<String, String> entry : entries) {
                if (entry.getValue().equals(qi)) {
                    list.add(entry.getKey());
                }
            }
        }
        return list;
    }
}